package lock_condition;

public class MailBox<T> extends BufferLimitato<T> {
	public MailBox(int n) {
		super(n);
	}

	public synchronized T get() {
		while (count == 0)
			try {
				wait();
			} catch (InterruptedException ignored) {
			}
		T ans = buffer[out];
		out = (out + 1) % n;
		count--;
		notifyAll();
		return ans;
	}// get

	public synchronized void put(T value) {
		while (count == n)
			try {
				wait();
			} catch (InterruptedException ignored) {
			}
		buffer[in] = value;
		in = (in + 1) % n;
		count++;
		notifyAll();
	}// put
}